package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@Aspect
@Component
@Slf4j
public class TimeAspect {
    @Pointcut("execution( * com.itheima.service.*.*(..))")
    public void log(){};
    @Around("log()")
    public Object timeAspect(ProceedingJoinPoint joinPoint) throws Throwable {
        Long start = System.currentTimeMillis();
        String methodName = joinPoint.getSignature().getName();
        String className = String.valueOf(joinPoint.getTarget().getClass().getName());
        String[] split = className.split("\\.", 5);
        Object object = joinPoint.proceed();
        Long end = System.currentTimeMillis();
        Long time = end - start;
        log.info("类名：{}， 方法名：{}，耗时：{}", split[4],methodName,time);
        return object;
    }
}
